﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using PetaPoco;

namespace DAL.MySQL
{
    public class toupiaoDAL
    {
        public Database db = DbScoure.DataBase();
        public toupiaoEntity GetOne(int id)
        {
            return db.SingleOrDefault<toupiaoEntity>("select * from toupiao where id=@0", id);
        }


        public List<toupiaoEntity> GetList(string where, string order, params object[] args)
        {
            var list = db.Fetch<toupiaoEntity>("select * from toupiao where 1=1 " + where + " order by " + order + ",ID desc", args);
            return list;
        }

        public Page<toupiaoEntity> GetPageList(int pagenum, int pagesize, string where, string order, params object[] args)
        {
            var pagelist = db.Page<toupiaoEntity>(pagenum, pagesize, "select * from toupiao where 1=1 " + where + " order by " + order + ",ID desc", args);
            return pagelist;
        }

        public int Update(object obj, int ID)
        {
            return db.Update("toupiao", "ID", obj, ID);
        }
        public toupiaoEntity Save(toupiaoEntity model)
        {
            db.Save("toupiao", "ID", model);
            return model;
        }

        public bool Del(int id)
        {
            try
            {
                db.Delete("toupiao", "ID", null, id);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public bool Del(toupiaoEntity model)
        {
            try
            {
                db.Delete("toupiao", "ID", model);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
